<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>04猜数字练习</title>
</head>
<body>
<h3>生成一个1~100的随机数</h3>
<input type="text" placeholder="请输入您猜的数字">
<button onclick="guess()">点我验证</button>
<h3>小提示： <span></span></h3>

<script>
    let count = 0
    let n = parseInt(Math.random() * 100 + 1);
    console.log('输出随机生成的小数' + n);
    function guess() {
        var numE = document.querySelector('input').value
        var s = document.querySelector('span');
       if(isNaN(numE )){
           alert('请输入数字');
           return;
       }

        count++;
        if (n == numE) {
            s.innerHTML = '恭喜你'+count+'次猜对了';
        } else if (n > numE) {
            s.innerHTML = '猜小了';
        } else {
            s.innerHTML = '猜大了';
        }



    }

</script>
</body>
</html>